unit Unit5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, ExtCtrls;

type
  TForm5 = class(TForm)
    StatusBar1: TStatusBar;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Timer1: TTimer;
    Button1: TButton;
    GroupBox2: TGroupBox;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;
    Label11: TLabel;
    Label12: TLabel;
    GroupBox3: TGroupBox;
    Label13: TLabel;
    Label14: TLabel;
    Label15: TLabel;
    Label16: TLabel;
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Renew;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    allRecv:DWORD;
    allSent:DWORD;
    allConn:DWORD;
    allWkgTime:DWORD;

    allPacked:DWORD;
  end;

var
  Form5: TForm5;

implementation

{$R *.dfm}

procedure TForm5.FormCreate(Sender: TObject);
begin
  allRecv:=0;
  allSent:=0;
  allConn:=0;
  allWkgTime:=0;
  allPacked:=0;
end;

procedure TForm5.FormShow(Sender: TObject);
begin
  Renew;
end;

function SizeDiv(Sz:DWORD; postB:BOOL):String;
var
  pre:Byte;
const
  cpre : array [1..5] of char = ('K', 'M', 'G', 'T', 'E');
begin
  pre:=0;
  while Sz >= 1024 do
  begin
    inc(pre);
    Sz:=Sz div 1024;
  end;
  Result:=IntToStr(Sz)+' ';
  if pre>0 then
    Result:=Result+cpre[pre];
  if postB then
    Result:=Result+'B';
end;

procedure TForm5.Renew;
begin
  Label4.Caption:=SizeDiv(allSent,True);
  Label5.Caption:=SizeDiv(allRecv,True);
  Label6.Caption:=IntToStr(allConn);

  if Integer(allPacked)>0 then
    Label16.Caption:=SizeDiv(allPacked,True)
  else
    Label16.Caption:='0';

  if allWkgTime=0 then exit;
  Label10.Caption:=SizeDiv(Round(allRecv*60/allWkgTime),True)+'pm';
  Label11.Caption:=SizeDiv(Round(allSent*60/allWkgTime),True)+'pm';
  Label12.Caption:=SizeDiv(Round(allConn*60/allWkgTime),False)+' per min.';

  Label14.Caption:=IntToStr(Round(allWkgTime/60))+' min.';
end;

procedure TForm5.Timer1Timer(Sender: TObject);
begin
  Renew;
end;

procedure TForm5.Button1Click(Sender: TObject);
begin
  Close;
end;

end.
